home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / comint / dbx.el.z / dbx.el
Encoding:
Text File  |  1998-05-21  |  6.1 KB  |  174 lines

  1. ;;; dbx.el --- run dbx under Emacs
  2.  
  3. ;; Copyright (C) 1988 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Masanobu UMEDA (umerin@flab.fujitsu.junet)
  6. ;; Keywords: c, unix, tools, debugging
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ;; 02111-1307, USA.
  24.  
  25. ;;; Synched up with: Not in FSF
  26.  
  27. ;;; Code:
  28.  
  29. (require 'comint)
  30.  
  31. (defvar dbx-trace-flag nil
  32.   "Dbx trace switch.")
  33.  
  34. (defvar dbx-process nil
  35.   "The process in which dbx is running.")
  36.  
  37. (defvar dbx-break-point
  38.   "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
  39.   "Regexp of pattern that dbx writes at break point.")
  40.  
  41. (defvar inferior-dbx-mode-map nil)
  42. (if inferior-dbx-mode-map
  43.     nil
  44.   (setq inferior-dbx-mode-map (make-sparse-keymap))
  45.   (set-keymap-name inferior-dbx-mode-map 'inferior-dbx-mode-map)
  46.   (set-keymap-parent inferior-dbx-mode-map comint-mode-map)
  47.   (define-key inferior-dbx-mode-map "\C-c\C-w" 'dbx-where)
  48.   (define-key inferior-dbx-mode-map "\C-c\C-t" 'dbx-trace-mode)
  49.   (define-key ctl-x-map " " 'dbx-stop-at))
  50.  
  51. (defun inferior-dbx-mode ()
  52.   "Major mode for interacting with an inferior dbx process.
  53.  
  54. The following commands are available:
  55. \\{inferior-dbx-mode-map}
  56.  
  57. Entry to this mode calls the value of dbx-mode-hook with no arguments,
  58. if that value is non-nil.  Likewise with the value of comint-mode-hook.
  59. dbx-mode-hook is called after comint-mode-hook.
  60.  
  61. You can display the debugging program in other window and point out
  62. where you are looking at using the command \\[dbx-where].
  63.  
  64. \\[dbx-trace-mode] toggles dbx-trace mode. In dbx-trace mode,
  65. debugging program is automatically traced using output from dbx.
  66.  
  67. The command \\[dbx-stop-at] sets break point at current line of the
  68. program in the buffer. Major mode name of the buffer must be in
  69. dbx-language-mode-list.
  70.  
  71. Commands:
  72.  
  73. Return at end of buffer sends line as input.
  74. Return not at end copies line, sans any dbx prompt, to end and sends it.
  75. \\[shell-send-eof] sends end-of-file as input.
  76. \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
  77. \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
  78. \\[comint-stop-subjob] stops, likewise. \\[comint-quit-subjob] sends quit signal, likewise.
  79. \\[dbx-where] displays debugging program in other window and
  80.  points out where you are looking at.
  81. \\[dbx-trace-mode] toggles dbx-trace mode.
  82. \\[dbx-stop-at] sets break point at current line."
  83.   (interactive)
  84.   (kill-all-local-variables)
  85.   (comint-mode)
  86.   (use-local-map inferior-dbx-mode-map)
  87.   (setq major-mode 'inferior-dbx-mode
  88.     mode-name "Inferior dbx"
  89.     comint-prompt-regexp "^[^)]*dbx) *")
  90.   (make-local-variable 'dbx-trace-flag)
  91.   (or (assq 'dbx-trace-flag minor-mode-alist)
  92.       (setq minor-mode-alist
  93.         (cons '(dbx-trace-flag " Trace") minor-mode-alist)))
  94.   (run-hooks 'dbx-mode-hook))
  95.  
  96. (defun run-dbx (path)
  97.   "Run inferior dbx process on PROGRAM, with I/O via buffer *dbx-PROGRAM*."
  98.   (interactive "fProgram to debug: ")
  99.   (setq path (expand-file-name path))
  100.   (let ((file (file-name-nondirectory path)))
  101.     (switch-to-buffer (concat "*dbx-" file "*"))
  102.     (setq default-directory (file-name-directory path))
  103.     (switch-to-buffer (make-comint (concat "dbx-" file) "dbx" nil file)))
  104.   (setq dbx-process (get-buffer-process (current-buffer)))
  105.   (set-process-filter dbx-process 'dbx-filter)
  106.   (inferior-dbx-mode))
  107.  
  108. (defun dbx-trace-mode (arg)
  109.   "Toggle dbx-trace mode.
  110. With arg, turn dbx-trace mode on iff arg is positive.
  111. In dbx-trace mode, user program is automatically traced."
  112.   (interactive "P")
  113.   (if (not (eql major-mode 'inferior-dbx-mode))
  114.       (error "dbx-trace mode is effective in inferior-dbx mode only."))
  115.   (setq dbx-trace-flag
  116.     (if (null arg)
  117.         (not dbx-trace-flag)
  118.       (> (prefix-numeric-value arg) 0)))
  119.   ;; Force mode line redisplay
  120.   (set-buffer-modified-p (buffer-modified-p)))
  121.  
  122. (defun dbx-filter (process string)
  123.   "Trace debugging program automatically if dbx-trace-flag is not nil."
  124.   (save-excursion
  125.     (set-buffer (process-buffer process))
  126.     (goto-char (point-max))
  127.     (let ((beg (point)))
  128.       (insert-before-markers string)
  129.       (if dbx-trace-flag        ;Trace mode is on?
  130.       (dbx-where beg t)))
  131.     (if (process-mark process)
  132.     (set-marker (process-mark process) (point-max))))
  133.   (if (eq (process-buffer process)
  134.       (current-buffer))
  135.       (goto-char (point-max)))
  136.   )
  137.  
  138. (defun dbx-where (&optional begin quiet)
  139.   "Display dbx'ed program in other window and point out where you are looking.
  140. BEGIN bounds the search. If QUIET, just return nil (no error) if fail."
  141.   (interactive)
  142.   (let (file line)
  143.     (save-excursion
  144.       (if (re-search-backward dbx-break-point begin quiet)
  145.       (progn
  146.         (setq line (buffer-substring (match-beginning 1) (match-end 1)))
  147.         (setq file (buffer-substring (match-beginning 2) (match-end 2)))
  148.         )))
  149.     (if (and file line)            ;Find break point?
  150.     (progn
  151.       (find-file-other-window (expand-file-name file nil))
  152.       (goto-line (string-to-int line)) ;Jump to the line
  153.       (beginning-of-line)
  154.       (setq overlay-arrow-string "=>")
  155.       (or overlay-arrow-position 
  156.           (setq overlay-arrow-position (make-marker)))
  157.       (set-marker overlay-arrow-position (point) (current-buffer))
  158.       (other-window 1))        ;Return to dbx
  159.       )))
  160.  
  161. (defun dbx-stop-at ()
  162.   "Set break point at current line."
  163.   (interactive)
  164.   (let ((file-name (file-name-nondirectory buffer-file-name))
  165.     (line (save-restriction
  166.         (widen)
  167.         (1+ (count-lines 1 (point))))))
  168.     (process-send-string dbx-process
  169.              (concat "stop at \"" file-name "\":" line "\n"))))
  170.  
  171. (provide 'dbx)
  172.  
  173. ;;; dbx.el ends here
  174.